package com.jiangjiang.eshop.wms.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiangjiang.eshop.wms.convert.GoodsAllocationConvert;
import com.jiangjiang.eshop.wms.dao.GoodsAllocationMapper;
import com.jiangjiang.eshop.wms.domain.GoodsAllocationEntity;
import com.jiangjiang.eshop.wms.dto.AllocationQueryPageDTO;
import com.jiangjiang.eshop.wms.dto.GoodsAllocationDTO;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName GoodsAllocationService
 * @Description TODO
 * @Author jhw
 * @Date 2021/9/13 6:40
 * @Version 1.0
 **/
@Service
public class WmsGoodsAllocationService extends ServiceImpl<GoodsAllocationMapper, GoodsAllocationEntity> {

    @Autowired
    private GoodsAllocationConvert goodsAllocationConvert;

    /**
     * 货位数据分页查询
     * @param dto 查询条件
     * @return 查询结果
     */
    public Page<GoodsAllocationDTO> queryForPage(AllocationQueryPageDTO dto){
        Page<GoodsAllocationEntity> page = new Page<>(dto.getPageNo(), dto.getPageSize(), true);
        LambdaQueryWrapper<GoodsAllocationEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Strings.isNotEmpty(dto.getCode()), GoodsAllocationEntity::getCode, dto.getCode());
        return goodsAllocationConvert.convertPage2DTO(this.getBaseMapper().selectPage(page, wrapper));
    }


    /**
     * 根据id查询货位数据
     * @param id 货位主键
     * @return 查询结果
     */
    public GoodsAllocationDTO queryById(Long id){
        return goodsAllocationConvert.convertEntity2DTO(this.getById(id));
    }

    /**
     * 保存货位数据
     * @param dto 货位数据
     * @return 处理结果
     */
    public Boolean save(GoodsAllocationDTO dto){
        return this.save(goodsAllocationConvert.convertDTO2Entity(dto));
    }


    public void queryBySkuId(Long goodsSkuId) {
    }
}
